home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
adg_1_3.zip
/
DLGTECH.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-21
|
10KB
|
328 lines
/****************************************************************************
Module name: DlgTech.C
Programmer : Jeffrey M. Richter.
*****************************************************************************/
#include "..\nowindws.h"
#undef NOCOLOR
#undef NOCTLMGR
#undef NOGDI
#undef NOKERNEL
#undef NOMB
#undef NOMEMMGR
#undef NOMENUS
#undef NOMSG
#undef NOSHOWWINDOW
#undef NOUSER
#undef NOWINMESSAGES
#undef NOWINOFFSETS
#undef NOWINSTYLES
#include <windows.h>
#include "dlg-opts.h"
#include "dlg-mdls.h"
#include "dlg-dyna.h"
#include "dlgtech.h"
#include "dialog.h"
char _szAppName[] = "DlgTech";
static HWND _hDlgDynamic = NULL;
static HWND _hDlgModalLess = NULL;
HANDLE _hInstance = NULL; // Our instance handle
BOOL NEAR PASCAL RegisterAppWndClass (HANDLE hInstance);
LONG FAR PASCAL AppWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL FAR PASCAL SWPDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
BOOL FAR PASCAL AboutDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpszCmdLine, int cmdShow) {
MSG msg;
HWND hWnd;
_hInstance = hInstance;
if (hPrevInstance == NULL)
if (!RegisterAppWndClass(hInstance))
return(0);
hWnd = CreateWindow(_szAppName, _szAppName,
WS_OVERLAPPED | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION |
WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME,
CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, 0);
if (hWnd == NULL) return(0);
ShowWindow(hWnd, cmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0)) {
if (!IsWindow(_hDlgDynamic) || !IsDialogMessage(_hDlgDynamic, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(0);
}
BOOL NEAR PASCAL RegisterAppWndClass (HANDLE hInstance) {
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.lpfnWndProc = AppWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(hInstance, _szAppName);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = COLOR_WINDOW + 1;
WndClass.lpszMenuName = _szAppName;
WndClass.lpszClassName = _szAppName;
return(RegisterClass(&WndClass));
}
// ***************************************************************************
// This function processes all messages sent to the main window.
LONG FAR PASCAL AppWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
BOOL fCallDefProc = FALSE;
LONG lResult = 0;
static FARPROC fpProcModeless;
FARPROC fpProc;
GLOBALHANDLE hMem;
int nResult;
char szBuf[100], szName[50];
switch (wMsg) {
case WM_CREATE:
_hDlgModalLess =
CreateModalLessDlgBox(_hInstance, "ModalLess", hWnd,
MakeProcInstance(ModalLessDlgProc, _hInstance), 0);
if (_hDlgModalLess == NULL) {
MessageBox(hWnd, "Can't create modalless dialog box.",
_szAppName, MB_OK);
EnableMenuItem(GetMenu(hWnd), IDM_MODALLESSDEMO,
MF_BYCOMMAND | MF_GRAYED);
}
break;
case WM_CLOSE:
if (_hDlgModalLess)
DestroyModalLessDlgBox(_hDlgModalLess);
fCallDefProc = TRUE;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch (wParam) {
case IDM_OPTIONSDEMO:
fpProc = MakeProcInstance(OptionsDlgProc, _hInstance);
DialogBox(_hInstance, "Options", hWnd, fpProc);
FreeProcInstance(fpProc);
break;
case IDM_DYNAMICMODALDEMO:
hMem = BuildDynamicDlgBox(FALSE);
if (hMem == NULL) {
MessageBox(hWnd, "Insufficient memory.", _szAppName, MB_OK);
break;
}
fpProc = MakeProcInstance(DynamicDlgProc, _hInstance);
DialogBoxIndirect(_hInstance, hMem, hWnd, fpProc);
FreeProcInstance(fpProc);
GlobalFree(hMem);
break;
case IDM_DYNAMICMODELESSDEMO:
if (_hDlgDynamic != NULL) {
DestroyWindow(_hDlgDynamic);
_hDlgDynamic = NULL;
CheckMenuItem(GetMenu(hWnd), wParam, MF_BYCOMMAND | MF_UNCHECKED);
FreeProcInstance(fpProcModeless);
break;
}
hMem = BuildDynamicDlgBox(TRUE);
if (hMem == NULL) {
MessageBox(hWnd, "Insufficient memory.", _szAppName, MB_OK);
break;
}
fpProcModeless = MakeProcInstance(DynamicDlgProc, _hInstance);
_hDlgDynamic = CreateDialogIndirect(_hInstance,
GlobalLock(hMem), hWnd, fpProcModeless);
GlobalUnlock(hMem);
GlobalFree(hMem);
CheckMenuItem(GetMenu(hWnd), wParam, MF_BYCOMMAND | MF_CHECKED);
break;
case IDM_MODALLESSDEMO:
nResult = ModalLessDlgBox(_hDlgModalLess, hWnd, 0);
GetDlgItemText(_hDlgModalLess, ID_NAME, szName, sizeof(szName));
wsprintf(szBuf, "Button: %s, Name: %s",
(nResult == IDOK) ? (LPSTR) "Ok" : (LPSTR) "Cancel",
(LPSTR) szName);
MessageBox(hWnd, szBuf, _szAppName, MB_OK);
break;
case IDM_SETWINDOWPOSDEMO:
fpProc = MakeProcInstance(SWPDlgProc, _hInstance);
DialogBox(_hInstance, "SetWindowPos", hWnd, fpProc);
FreeProcInstance(fpProc);
break;
case IDM_ABOUT:
// Display about box
fpProc = MakeProcInstance(AboutDlgProc, _hInstance);
DialogBox(_hInstance, "About", hWnd, fpProc);
FreeProcInstance(fpProc);
break;
default:
// Any option's that we do not process should be
// passed to DefWindowProc.
fCallDefProc = TRUE;
break;
}
break;
default:
fCallDefProc = TRUE; break;
}
if (fCallDefProc)
lResult = DefWindowProc(hWnd, wMsg, wParam, lParam);
return(lResult);
}
//****************************************************************************
// Functions for the SetWindowPos Dialog Box Demonstration.
BOOL FAR PASCAL SWPDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
BOOL fProcessed = TRUE;
HWND hWndControl;
WORD wDlgWidth, wDlgHeight;
switch (wMsg) {
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch (wParam) {
case IDOK:
case IDCANCEL:
if (HIWORD(lParam) == BN_CLICKED)
EndDialog(hDlg, wParam);
break;
case ID_CHANGETABORDER:
if (HIWORD(lParam) != BN_CLICKED)
break;
// Order is "&Name:", "edit", "Over &25".
// Move "Over &25" after "&Name:" field.
SetWindowPos(GetDlgItem(hDlg, ID_OVER25),
GetDlgItem(hDlg, ID_NAMETEXT),
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
// Order is "&Name:", "Over &25", "edit".
// Move "&Name:" after "Over &25" field.
SetWindowPos(GetDlgItem(hDlg, ID_NAMETEXT),
GetDlgItem(hDlg, ID_OVER25),
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
// Order is "Over &25", "&Name:", "edit".
// Set the focus to the control after this button..
SetFocus(GetNextDlgTabItem(hDlg, LOWORD(lParam), 0));
EnableWindow(LOWORD(lParam), FALSE);
break;
case ID_ADDCONTROL:
if (HIWORD(lParam) != BN_CLICKED)
break;
wDlgWidth = LOWORD(GetDialogBaseUnits());
wDlgHeight = HIWORD(GetDialogBaseUnits());
hWndControl = CreateWindow("scrollbar", "",
SBS_HORZ | WS_CHILD | WS_TABSTOP | WS_GROUP,
(64 * wDlgWidth) / 4, (36 * wDlgHeight) / 8,
(64 * wDlgWidth) / 4, (12 * wDlgHeight) / 8,
hDlg, ID_SCROLLBAR, _hInstance, 0);
SetWindowPos(hWndControl, LOWORD(lParam),
0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
// Set the focus to the control after this button..
SetFocus(GetNextDlgTabItem(hDlg, LOWORD(lParam), 0));
EnableWindow(LOWORD(lParam), FALSE);
break;
default:
break;
}
break;
default:
fProcessed = FALSE; break;
}
return(fProcessed);
}
//****************************************************************************
// Function for the About Box.
BOOL FAR PASCAL AboutDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
char szBuffer[100];
BOOL fProcessed = TRUE;
switch (wMsg) {
case WM_INITDIALOG:
// Set version static window to have date and time of compilation.
wsprintf(szBuffer, "%s at %s", (LPSTR) __DATE__, (LPSTR) __TIME__);
SetWindowText(GetDlgItem(hDlg, ID_VERSION), szBuffer);
break;
case WM_COMMAND:
switch (wParam) {
case IDOK:
case IDCANCEL:
if (HIWORD(lParam) == BN_CLICKED)
EndDialog(hDlg, wParam);
break;
default:
break;
}
break;
default:
fProcessed = FALSE;
break;
}
return(fProcessed);
}